home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1320 / 1320.xpi / chrome / gmanager.jar / content / overlayToolbarTooltip.js < prev   
Text File  |  2010-01-22  |  8KB  |  226 lines

  1. // Gmail Manager
  2. // By Todd Long <longfocus@gmail.com>
  3. // http://www.longfocus.com/firefox/gmanager/
  4.  
  5. var gmanager_ToolbarTooltip = new function()
  6. {
  7.   this.__proto__ = new gmanager_BundlePrefix("gmanager-toolbar-tooltip-");
  8.   
  9.   this.buildTooltip = function(aTooltip)
  10.   {
  11.     var manager = Components.classes["@longfocus.com/gmanager/manager;1"].getService(Components.interfaces.gmIManager);
  12.     var account = aTooltip.parentNode.displayAccount;
  13.     
  14.     // Clear the menu
  15.     gmanager_Utils.clearKids(aTooltip);
  16.     
  17.     // Check if the account exists
  18.     if (account != undefined)
  19.     {
  20.       // Account Header
  21.       aTooltip.appendChild(this._buildAccountHeader(account));
  22.       
  23.       // Check if the account is logged in
  24.       if (account.loggedIn)
  25.       {
  26.         // Account Details
  27.         aTooltip.appendChild(this._buildAccountDetails(account));
  28.       }
  29.     }
  30.     else
  31.     {
  32.       // Account Status
  33.       aTooltip.appendChild(this._buildMessage(account));
  34.     }
  35.     
  36.     return !gmanager_ToolbarMove.isActive();
  37.   }
  38.   
  39.   this._buildAccountHeader = function(aAccount)
  40.   {
  41.     var elParent = document.createElement("hbox");
  42.     elParent.setAttribute("style", "font-size:12px; margin-bottom:4px;");
  43.     
  44.     // Status Icon
  45.     var el = document.createElement("image");
  46.     el.setAttribute("class", "gmanager-icon");
  47.     el.setAttribute("iconsize", "small");
  48.     el.setAttribute("icontype", aAccount.type);
  49.     el.setAttribute("status", gmanager_Utils.toStyleStatus(aAccount.status));
  50.     el.setAttribute("newMail", (aAccount.unread > 0 ? "true" : "false"));
  51.     elParent.appendChild(el);
  52.     
  53.     // Account Email
  54.     el = document.createElement("label");
  55.     el.setAttribute("class", "gmanager-bold");
  56.     el.setAttribute("value", gmanager_Utils.toUnicode(aAccount.alias));
  57.     elParent.appendChild(el);
  58.     
  59.     var bundleKey = null;
  60.     
  61.     if (aAccount.status == Components.interfaces.gmIService.STATE_CONNECTING)
  62.       bundleKey = (aAccount.loggedIn ? "checking-mail" : "logging-in");
  63.     else
  64.       bundleKey = (aAccount.loggedIn ? "logged-in" : "logged-out");
  65.     
  66.     // Account Status
  67.     el = document.createElement("label");
  68.     el.setAttribute("value", this.getString(bundleKey));
  69.     elParent.appendChild(el);
  70.     
  71.     return elParent;
  72.   }
  73.   
  74.   this._buildAccountDetails = function(aAccount)
  75.   {
  76.     var elParent = document.createElement("vbox");
  77.     elParent.setAttribute("style", "font-size:11px; margin-left:6px;");
  78.     
  79.     // Inbox Unread
  80.     var el = document.createElement("label");
  81.     el.setAttribute("flex", "1");
  82.     el.setAttribute("value", this.getFString("inbox-unread", [aAccount.inboxUnread]));
  83.     elParent.appendChild(el);
  84.     
  85.     // Saved Drafts
  86.     el = document.createElement("label");
  87.     el.setAttribute("value", this.getFString("saved-drafts", [aAccount.savedDrafts]));
  88.     el.setAttribute("hidden", (aAccount.savedDrafts == 0));
  89.     elParent.appendChild(el);
  90.     
  91.     // Spam Unread
  92.     el = document.createElement("label");
  93.     el.setAttribute("value", this.getFString("spam-unread", [aAccount.spamUnread]));
  94.     el.setAttribute("hidden", (aAccount.spamUnread == 0));
  95.     elParent.appendChild(el);
  96.     
  97.     if (true) // TODO: Add preference to show/hide labels
  98.     {
  99.       var elHbox = document.createElement("hbox");
  100.       var elGrid = document.createElement("grid");
  101.       var elRows = document.createElement("rows");
  102.       var labels = aAccount.getLabels({});
  103.       
  104.       elGrid.setAttribute("style", "margin:6px 4px;");
  105.       
  106.       for (var i = 0; i < labels.length; i++)
  107.       {
  108.         var isUnread = (labels[i].unread > 0);
  109.         var elRow = document.createElement("row");
  110.         elRow.setAttribute("align", "center");
  111.         elRow.setAttribute("class", (isUnread ? "gmanager-bold" : ""));
  112.         
  113.         // Label Name
  114.         el = document.createElement("label");
  115.         el.setAttribute("value", gmanager_Utils.toUnicode(labels[i].name));
  116.         elRow.appendChild(el);
  117.         
  118.         // Label Unread
  119.         el = document.createElement("label");
  120.         el.setAttribute("value", labels[i].unread);
  121.         el.setAttribute("style", "margin-left:4px");
  122.         elRow.appendChild(el);
  123.         
  124.         if (isUnread || !aAccount.getBoolPref("toolbar-tooltip-show-labels")) // TODO: Add preference to show/hide labels with unread mail
  125.           elRows.appendChild(elRow);
  126.       }
  127.       
  128.       if (elRows.hasChildNodes())
  129.       {
  130.         elGrid.appendChild(elRows);
  131.         elHbox.appendChild(elGrid);
  132.         elParent.appendChild(elHbox);
  133.       }
  134.     }
  135.     
  136.     // Space Used
  137.     el = document.createElement("label");
  138.     el.setAttribute("value", this.getFString("space-used", [aAccount.spaceUsed, aAccount.percentUsed, aAccount.totalSpace]));
  139.     elParent.appendChild(el);
  140.     
  141.     if (aAccount.getBoolPref("toolbar-tooltip-show-snippets"))
  142.     {
  143.       // Snippets
  144.       var snippets = aAccount.getSnippets({});
  145.       
  146.       if (snippets.length > 0)
  147.       {
  148.         // Separator
  149.         el = document.createElement("separator");
  150.         el.setAttribute("class", "groove");
  151.         el.setAttribute("style", "margin:6px 0 0 0;");
  152.         elParent.appendChild(el);
  153.         
  154.         for (var i = 0; i < Math.min(10, snippets.length); i++)
  155.         {
  156.           var elHbox = document.createElement("hbox");
  157.           elHbox.setAttribute("flex", "1");
  158.           elHbox.setAttribute("style", "margin-top:8px");
  159.           
  160.           el = document.createElement("label");
  161.           el.setAttribute("crop", "end");
  162.           el.setAttribute("flex", "1");
  163.           el.setAttribute("class", "gmanager-bold");
  164.           el.setAttribute("style", "font-size:10px;");
  165.           el.setAttribute("value", gmanager_Utils.toUnicode(snippets[i].from) + " > " + gmanager_Utils.toUnicode(snippets[i].subject));
  166.           elHbox.appendChild(el);
  167.           
  168.           el = document.createElement("label");
  169.           el.setAttribute("class", "gmanager-bold");
  170.           el.setAttribute("value", gmanager_Utils.toUnicode(snippets[i].time));
  171.           elHbox.appendChild(el);
  172.           elParent.appendChild(elHbox);
  173.           
  174.           el = document.createElement("description");
  175.           el.setAttribute("crop", "end");
  176.           el.setAttribute("style", "font-size:9px; margin:2px 0 0 0;");
  177.           el.setAttribute("value", gmanager_Utils.toUnicode(snippets[i].msg));
  178.           elParent.appendChild(el);
  179.         }
  180.         
  181.         el = document.createElement("separator");
  182.         el.setAttribute("class", "thin");
  183.         elParent.appendChild(el);
  184.       }
  185.     }
  186.     
  187.     return elParent;
  188.   }
  189.   
  190.   this._buildMessage = function(aAccount)
  191.   {
  192.     var bundleKey = "msg-logged-out";
  193.     
  194.     if (aAccount != undefined)
  195.     {
  196.       switch (aAccount.status)
  197.       {
  198.         case Components.interfaces.gmIService.STATE_CONNECTING:
  199.           bundleKey = "msg-connecting";
  200.           break;
  201.         case Components.interfaces.gmIService.STATE_ERROR_PASSWORD:
  202.           bundleKey = "msg-error-password";
  203.           break;
  204.         case Components.interfaces.gmIService.STATE_ERROR_NETWORK:
  205.           bundleKey = "msg-error-network";
  206.           break;
  207.         case Components.interfaces.gmIService.STATE_ERROR_TIMEOUT:
  208.           bundleKey = "msg-error-timeout";
  209.           break;
  210.       }
  211.     }
  212.     
  213.     var elParent = document.createElement("vbox");
  214.     elParent.setAttribute("style", "font-size:12px; margin-left:3px;");
  215.     
  216.     var bundleString = this.getString(bundleKey).split("|");
  217.     for (var i = 0; i < bundleString.length; i++)
  218.     {
  219.       var el = document.createElement("label");
  220.       el.setAttribute("value", bundleString[i]);
  221.       elParent.appendChild(el);
  222.     }
  223.     
  224.     return elParent;
  225.   }
  226. }